<template>
	<view class="page">
		<view class="section-bp margin-bottom-xs" v-for="(item, index) in companyList">
			<view class="flex padding-m" @click="select(item,index)">
				<view class="flex-3">{{item.companyName}}</view>
				<uni-icons type="checkmarkempty" color="#486cd4" v-if="item.id === accountSetsId"></uni-icons>
			</view>
		</view>
	</view>
</template>

<script>
	import common from '../../js/api/common'
	const app = getApp();
	export default {
		data() {
			return {
				companyList: [],
				accountSetsId:'',
			}
		},
		onLoad() {
			this.init()
		},
		methods: {
			init() {
				common.init().then((res) => {
					uni.setStorageSync(app.globalData.data.cache_config_info_key, res.roleInfo);
					this.companyList = res.user.accountSetsList
					this.accountSetsId = res.user.accountSets.id;
				})
			},
			select(item,index){
				if(item.id === this.accountSetsId){
					return;
				}else{
					common.changeAccountSets({accountSetsId:item.id}).then((res)=>{
						app.globalData.showToast("切换成功");
						uni.reLaunch({
						  url: '/pages/home/home'
						})
					})
				}
			}
		}
	}
</script>

<style>

</style>